import 'package:flutter/material.dart';
import 'package:ytbusiness/utils/screen_adaptation.dart';
import 'package:ytbusiness/utils/asset_util.dart';
import 'package:ytbusiness/widgets/widgets.dart';
import 'package:ytbusiness/config/yt_theme.dart';

/// 扫码登录 结果页面
///
/// 本模块函数，加载状态类组件_ScannerResultState
class ScannerResult extends StatefulWidget {
  ///扫码返回的文本
  final Map<String, dynamic> arguments;

  ///构造方法
  const ScannerResult({Key key, this.arguments}) : super(key: key);

  @override
  _ScannerResultState createState() => _ScannerResultState();
}

class _ScannerResultState extends State<ScannerResult> {
  String _scannerTxt;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    //根据 arguments 请求接口
    _scannerTxt = widget.arguments["scanner_txt"] as String;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: noTitleBar(context, leftTxt: "关闭"),
      body: _body(),
    );
  }

  Widget _body() {
    return Column(
      children: [
        Expanded(
            flex: 1,
            child: ListView(
              shrinkWrap: true,
              children: [
                Container(
                  margin: EdgeInsets.only(top: setWidth(94)),
                  child: Image.asset(
                    AssetUtil.icon("ic_pc"),
                    width: setWidth(106),
                    height: setWidth(67),
                  ),
                ),
                Container(
                  margin: EdgeInsets.only(top: setWidth(25)),
                  child: Text(
                    "Windows登录确认",
                    textAlign: TextAlign.center,
                    style: TextStyle(
                        fontSize: setSp(18), color: Color(0xFF333333)),
                  ),
                ),
                Container(
                  margin: EdgeInsets.only(top: setWidth(18)),
                  child: Text(
                    _scannerTxt == "登录"
                        ? "即将在电脑上登录连接汽配商协同管理平台"
                        : "二维码已失效，请重新扫码登录",
                    textAlign: TextAlign.center,
                    style: TextStyle(
                        fontSize: setSp(12),
                        color: _scannerTxt == "登录"
                            ? Color(0xFF999999)
                            : Color(0xFFff4d4d)),
                  ),
                ),
              ],
            )),
        Container(
          margin: EdgeInsets.only(bottom: setWidth(104)),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Container(
                  alignment: Alignment.center,
                  width: setWidth(160),
                  height: setWidth(33),
                  decoration: BoxDecoration(
                      color: YTTheme.theme,
                      borderRadius: BorderRadius.all(Radius.circular(4.0))),
                  child: Text(
                    _scannerTxt == "登录" ? "登录" : "重新扫码登录",
                    textAlign: TextAlign.center,
                    style: TextStyle(
                        fontSize: setSp(15), color: Color(0xFFFFFFFF)),
                  )),
              Container(
                margin: EdgeInsets.only(top: setWidth(27)),
                child: Text(
                  _scannerTxt == "登录" ? "取消登录" : "",
                  style:
                      TextStyle(fontSize: setSp(15), color: Color(0xFF37c2bb)),
                ),
              )
            ],
          ),
        )
      ],
    );
  }
}
